<template>
	<div class="padding-container preview-wrap">
    <div class="title-part">
		</div>
		<el-form ref="tableParams" :inline="true" :model="tableParams" size="small">
      <el-form-item :label="$root.lang.userinfo.buyLog.order.orderNo">
        <el-input v-model="tableParams.orderNo"></el-input>
      </el-form-item>
      <el-form-item :label="$root.lang.userinfo.buyLog.order.payState">
        <el-select v-model="tableParams.payState" :placeholder="$root.lang.userinfo.buyLog.order.select">
          <el-option :label="item.title" :value="item.value" :key="item.value" v-for="item in baseState.payState"></el-option>        
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="searchAction()" >{{ $root.lang.userinfo.buyLog.order.query }}</el-button>
        <el-button size="small" @click="searchAction(true)" >{{ $root.lang.userinfo.buyLog.order.empty }}</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="listLoading"
      :data="orderList"
      :empty-text="$root.lang.userinfo.buyLog.order.noData"
      size="small"
      border
      style="width: 100%"
      >
      <el-table-column
        align="center"
        :label="$root.lang.userinfo.buyLog.order.months">
        <template slot-scope="scope">
          <span>{{ scope.row.months | dataFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$root.lang.userinfo.buyLog.order.amount">
        <template slot-scope="scope">
          <span>{{ scope.row.amount | dataFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$root.lang.userinfo.buyLog.order.payState">
        <template slot-scope="scope">
          <span>{{ baseState.payState, scope.row.payState, '--' | matchValue }}</span>
        </template>
      </el-table-column>
      <el-table-column
        width="280"
        align="center"
        :label="$root.lang.userinfo.buyLog.order.orderNo">
        <template slot-scope="scope">
          <span>{{ scope.row.orderNo | dataFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$root.lang.userinfo.buyLog.order.creTime">
        <template slot-scope="scope">
          <span>{{ scope.row.creTime | dateFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$root.lang.userinfo.buyLog.order.completionTime">
        <template slot-scope="scope">
          <p>{{ scope.row.completionTime | dateFormat }}</p>
        </template>
      </el-table-column>
    </el-table>
	</div>
</template>

<script>
import '@/options/baseState'
export default {
	name: 'OrderList',
  components: {
    
  },
	data() {
		return {
			showDialog:false,
			tableParams:{
				orderNo: null,
				payState: 'SUCCESS',
				payType: 0,
				userId: this.Cookies.get('I'),
			},
			listLoading:false,
      orderList:[],
      baseState: baseState,
		}
	},
  methods: {
    getReceive(data) {
      this[data.key] = data.value
    },
    reloadTable() {
      this.searchAction(true);
    },
    searchAction(reset) {
      if(reset) {
        this.tableParams = {
          orderNo: null,
          payState: 'SUCCESS',
          payType: 0,
          userId: this.Cookies.get('I'),
        }
      } 
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      this.request({
          url: '/daliy/order/query',
          method: 'post',
          data: this.$root.optionProcess(this.tableParams)
        }).then(response => {
          this.orderList = response.rows
          this.listLoading = false
        }).catch(error => {
          this.orderList = []
          this.listLoading = false
          this.$message({
            message: error.errmsg,
            type: 'error',
            duration: 3 * 1000
          })
      })
    }
  },
  created() {
    this.fetchData()
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
	.padding-container {
		text-align:left;
		.title-part {
			text-align: left;
			font-size: 18px;
			padding-bottom: 20px;
		}
    .lang-select {
      margin-right: 10px;
      cursor: pointer;
    }
	}
</style>